#include <GLFW/glfw3.h>
#include <Math3D.hpp>

int main(){
	Matrix4 matrix;

	glfwInit();
	GLFWwindow* window = glfwCreateWindow(512, 512, "OpenGL", 0, 0);
	glfwMakeContextCurrent(window);
	
	float angle;
	
	while (!glfwWindowShouldClose(window)) {
		glfwPollEvents();
		
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		
		// rotate (while), scale, translate
		glColor3f(1, 1, 1);
		glMatrixMode(GL_MODELVIEW);
		matrix.loadIdentity();
		matrix.translate(0.5f, 0.5f, 0.0f);
		matrix.rotate(angle, 0, 1, 0);
		matrix.scale(0.3, 0.3, 0.3);
		glLoadMatrixf(matrix.getPtr());
		glBegin(GL_TRIANGLES);
			glVertex2f(-1,  1);
			glVertex2f( 1,  1);
			glVertex2f( 0, -1);
		glEnd();
		
		// rotateX (red), scale, translate
		glColor3f(1, 0, 0);
		glMatrixMode(GL_MODELVIEW);
		matrix.loadIdentity();
		matrix.translate(Vector3(-0.5f, 0.5f, 0.0f));
		matrix.rotateX(angle);
		matrix.scale(Vector3(0.3, 0.3, 0.3));
		glLoadMatrixf(matrix.getPtr());
		glBegin(GL_TRIANGLES);
			glVertex2f(-1,  1);
			glVertex2f( 1,  1);
			glVertex2f( 0, -1);
		glEnd();

		// rotateY (green), scale, translate
		glColor3f(0, 1, 0);
		glMatrixMode(GL_MODELVIEW);
		matrix.loadIdentity();
		matrix.translate(Vector3(-0.5f, -0.5f, 0.0f));
		matrix.rotateY(angle);
		matrix.scale(Vector3(0.3, 0.3, 0.3));
		glLoadMatrixf(matrix.getPtr());
		glBegin(GL_TRIANGLES);
			glVertex2f(-1,  1);
			glVertex2f( 1,  1);
			glVertex2f( 0, -1);
		glEnd();

		// rotateZ (blue), scale, translate
		glColor3f(0, 0, 1);
		glMatrixMode(GL_MODELVIEW);
		matrix.loadIdentity();
		matrix.translate(Vector3(0.5f, -0.5f, 0.0f));
		matrix.rotateZ(angle);
		matrix.scale(Vector3(0.3, 0.3, 0.3));
		glLoadMatrixf(matrix.getPtr());
		glBegin(GL_TRIANGLES);
			glVertex2f(-1,  1);
			glVertex2f( 1,  1);
			glVertex2f( 0, -1);
		glEnd();
		
		glfwSwapBuffers(window);
		
		angle += 0.01f;
	}
	glfwDestroyWindow(window);
	glfwTerminate();
	return 0;
}